package resource;

import dragon.security.handler.AuthenFailHandler;
import dragon.security.handler.AuthenSuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * 资源服务器
 * @author Administrator
 */
//@Configuration
//@EnableResourceServer
public class ResourceConfigurer extends ResourceServerConfigurerAdapter {

    @Autowired
    AuthenSuccessHandler authenSuccessHandler;

     @Autowired
    AuthenFailHandler authenFailHandler;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage("/login")
                .loginProcessingUrl("/login/form")
                .successHandler(authenSuccessHandler)
                .failureHandler(authenFailHandler)
                .and()
                .authorizeRequests()
                .antMatchers("/staff")
                .hasAnyRole("admin","staff")
                .antMatchers("/signup","/me")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .cors().disable();
    }
}
